﻿using Microsoft.SharePoint;

namespace Trentacular.SharePoint.FeatureReceivers
{
    /// <summary>
    /// Base class that makes the feature scope available as an argument to the
    /// FeatureActivated and FeatureDeactivating methods.
    /// </summary>
    /// <typeparam name="T">
    /// T is the class type of the scope of the feature (SPFarm, SPWebApplication,
    /// SPSite, or SPWeb).
    /// </typeparam>
    public abstract class BaseFeatureReceiver<T> : SPFeatureReceiver
    {
        /// <summary>
        /// Called when a feature is being activated.
        /// </summary>
        /// <param name="properties">The feature receiver properties.</param>
        public sealed override void FeatureActivated(
            SPFeatureReceiverProperties properties
            )
        {
            FeatureActivated((T)properties.Feature.Parent, properties);
        }

        /// <summary>
        /// Called when a feature is being activated.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="properties">The feature receiver properties.</param>
        public virtual void FeatureActivated(
            T scope,
            SPFeatureReceiverProperties properties
            )
        {

        }

        /// <summary>
        /// Called when a feature is being deactivated.
        /// </summary>
        /// <param name="properties">The feature receiver properties.</param>
        public sealed override void FeatureDeactivating(
            SPFeatureReceiverProperties properties
            )
        {
            FeatureDeactivating((T)properties.Feature.Parent, properties);
        }

        /// <summary>
        /// Called when a feature is being deactivated.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="properties">The feature receiver properties.</param>
        public virtual void FeatureDeactivating(
            T scope,
            SPFeatureReceiverProperties properties
            )
        {

        }

        /// <summary>
        /// Called when a feature is being installed.
        /// </summary>
        /// <param name="properties">The feature receiver properties.</param>
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            
        }

        /// <summary>
        /// Called when a feature is being uninstalled.
        /// </summary>
        /// <param name="properties">The feature receiver propertiess.</param>
        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            
        }
    }
}
